<?php 
	include_once('config/db.php');
	include_once('functions/item.php');
	include_once('functions/category.php');
	include_once('functions/reservation.php');
	
	if(isset($_REQUEST['i'])){
		$selected_items = getSelectedItems($_REQUEST['i']);
		$_SESSION['selected_ids'] = $_REQUEST['i'];
	}
	else if(isset($_SESSION['selected_ids'])){
		$selected_items = getSelectedItems($_SESSION['selected_ids']);
	}
	
	if(isset($_REQUEST['reserve_item'])){
		$items = $_REQUEST['r'];
		reserveItems($items, $_SESSION['user_id']);
		header('location:borrow_success.php');
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Borrower's Page</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
<link rel="stylesheet" href="assets/css/zebra_datepicker.css" type="text/css"/>
<link rel="stylesheet" href="assets/css/jquery-ui.css" type="text/css"/>
<link rel="stylesheet" href="assets/css/jquery.ptTimeSelect.css" type="text/css"/>
<script type="text/javascript" src="assets/script/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="assets/script/zebra_datepicker.js"></script>
<script type="text/javascript" src="assets/script/jquery.ptTimeSelect.js"></script>
<script type="text/javascript" src="assets/script/script.js"></script>
</head>

<body>

	<div id="header">
		<div id="logo">
		  <p>&nbsp;</p>
		  <div id="apDiv1"><img src="image/logo.png" alt="" width="500" height="100" /></div>
		  <p>&nbsp;</p>
		</div>
	</div>

	<div id="con-body">
	 <h4>Welcome: <a href="index.php"><?php echo $_SESSION['name'];?></a> | <a href="change.php">Change Password</a> | <a href="edit.php">Edit Profile</a> | <a href="logout.php">Logout</a>  </h4>
	<?php include('extension/left_bar.php');?>
	
	
	 
	 <?php if(isset($selected_items)):?>
	 <div class="container">
			<?php if($selected_items != 0):?>
				<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" style="width:100%;" id="save_reservation">
				<table width="100%" border="0" cellpadding="1" cellspacing="1">
				<thead>
					<tr>
						<th width="5%">QTY</th>
						<th width="5%">Name</th>
						<th width="5%">Requiring Subject</th>
						<th width="25%">Date</th>
						<th width="10%">Time</th>
						<th width="5%">Remove</th>
					</tr>
				</thead>
				<tbody>
				<?php $ctr = 1;?>
				<?php foreach($selected_items as $i):?>
					
					<tr class="tbl-row">
						<td><input type="text" name="r[<?php echo $ctr?>][qty]" value="1" class="qty"/></td>
						<td>
							<input type="hidden" name="r[<?php echo $ctr?>][id]" value="<?php echo $i['item_id']?>" />
							<input type="hidden" name="r[<?php echo $ctr?>][name]" value="<?php echo $i['item_name']; ?>"/>
							<?php echo $i['item_name'];?>
						</td>
						<td><input type="text" name="r[<?php echo $ctr?>][subject]" value="" class="subject"/></td>
						<td>
							<input type="text" name="r[<?php echo $ctr?>][from]" class="datepicker from" placeholder="From" readonly="readonly"/>
							<input type="text" name="r[<?php echo $ctr?>][to]" class="datepicker to" placeholder="To" readonly="readonly"/>
						</td>
						<td>
							<input type="text" name="r[<?php echo $ctr?>][time]" class="tpicker" placeholder="Pickup Time" readonly="readonly" value=""/>
						</td>
						<td><a href="#" class="remove">Remove</a></td>
					</tr>
					<?php $ctr++;?>
				<?php endforeach;?>
				</tbody>
				</table>
				<input type="submit" name="reserve_item" value="Save" />
				</form>
			<?php else:?>
				<div class="notice">No items available for this category</div>
			<?php endif;?>
	 </div>
	 <?php endif;?>
	<div id="clear">
	  <p>&nbsp;</p>
	</div>
	</div>
</body>
</html>